This set of routines provide a standard test and set facility. If the
lock is free then it is atomically locked, and control is returned to the
caller. If the lock is already locked, the caller either spins waiting
for the lock or gets queued. The locks are based in user address space
thus avoiding any system call overhead in the case where the lock is
available.
The actual algorithm used to implement these functions depends on whether
the system is a multiprocessor or a single processor. In the
multiprocessor case, if the lock is already locked, the caller will spin
(i.e. busy wait). The amount of time it spins depends on the function -
for _uuuu_ssss_ssss_eeee_tttt_llll_oooo_cccc_kkkk, a system chosen value is used, for _uuuu_ssss_cccc_ssss_eeee_tttt_llll_oooo_cccc_kkkk and
_uuuu_ssss_wwww_ssss_eeee_tttt_llll_oooo_cccc_kkkk the value of _s_p_i_n_s is used. If, after _s_p_i_n_s attempts to
acquire the lock have all failed, the function will either return
(_uuuu_ssss_cccc_ssss_eeee_tttt_llll_oooo_cccc_kkkk) or yield the processor (_uuuu_ssss_ssss_eeee_tttt_llll_oooo_cccc_kkkk, or _uuuu_ssss_wwww_ssss_eeee_tttt_llll_oooo_cccc_kkkk). The
yield is affected by calling _ssss_gggg_iiii_nnnn_aaaa_pppp(2). After returning from yield,
_uuuu_ssss_ssss_eeee_tttt_llll_oooo_cccc_kkkk and _uuuu_ssss_wwww_ssss_eeee_tttt_llll_oooo_cccc_kkkk will again attempt to acquire the lock _s_p_i_n_s
times. This will continue until the lock is finally acquired. Note that
if a process spends much of its time waiting for a lock without giving up
the processor, then the total throughput of the system may be reduced.
On the other hand, by giving up the processor too quickly, there is a
longer latency between when the lock is freed and the caller obtains the
lock.
The implementation of locks on single processor systems never spin; if
the lock is unavailable the caller is atomically queued. This queueing
operation suspends the calling process and forces a scheduling cycle.
Processes are removed from the queue in FIFO order when the lock is
released.
The appropriate lock algorithm is selected automatically at program
startup time. Different levels of debugging information can be requested
uuuusssssssseeeettttlllloooocccckkkk,,,, uuuusssswwwwsssseeeettttlllloooocccckkkk,,,, uuuussssccccsssseeeettttlllloooocccckkkk,,,, and uuuusssstttteeeessssttttlllloooocccckkkk will return a 1 if the
lock is acquired and a 0 if the lock is not acquired. uuuussssuuuunnnnsssseeeettttlllloooocccckkkk always
returns 0 if successful. On error, -1 is returned and _e_r_r_n_o is set to